## Fig. 1: error-reduction factor of Rep3 
from PyM import *

# Important points
O = (0,0); X = (0.5,0); Y = (0,1); Yh = (0,0.5); Xh =(0.19,0); U = (0.5,1); Uh=(0.5,0.5); P=(0.19,0.5)

t = ls(0,0.5,100)
def p1(p): return p**2*(3-2*p)  # computes p'
def erf(p): return p*(3-2*p)    # computes p'/p
def L(p): return 3*p            # linear approximation of p'/p for p small


# plotting
close('all')

eps=0.1

# axis setting
ax = plt.figure("Graph of p' and p'/p", figsize=(10,5))
plt.xlim(-eps,1+eps)
plt.ylim(-eps,1+eps)
plt.axis('off')

ruler(O,X, left_inc=0)
ruler(O,Y, left_inc=0)
seg(Y,U); seg(X,U); seg(Yh,Uh,dashing='--')
seg(Xh,P,dashing='--')
seg(O,Uh)
plot(t,p1(t),color='blue')
plot(t,erf(t), color='red')
plot(t[:67],L(t[:67]),color='black')

# labeling
lable(O,'$0$',dx=-eps/4,dy=-0.6*eps, fs=14)
lable(Xh,'0.19',dx=-0.4*eps,dy=-0.7*eps, fs=14)
lable(X,'1/2',dx=-eps/5,dy=-0.7*eps, fs=14)
lable(Yh,'1/2',dx=-0.5*eps,dy=-0.2*eps, fs=14)
lable(Y,'1',dx=-0.3*eps,dy=-0.2*eps, fs=14)
lable((0.56,0),r"$p$",dx=0,dy=-0.2*eps, fs=18)
lable((0.25,0.25),r"$p$",dx=0,dy=0.5*eps, fs=18)
lable((0.35,p1(0.35)),r"$p'$",dx=0,dy=-0.6*eps, fs=18, color='blue')
lable((0.33,0.7),r"$p'/p$",dx=0,dy=0, fs=18, color='red')
lable((0.19,0.75),r"$3p$",dx=0,dy=0, fs=18, color='black')

plt.show()
